home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / 1.2 / scripts / neon-logo.scm.z / neon-logo.scm
Text File  |  2002-07-08  |  7KB  |  221 lines

  1. ;  NEON
  2. ;  Create a text effect that simulates neon lighting
  3.  
  4. (define (set-pt a index x y)
  5.   (prog1
  6.    (aset a (* index 2) x)
  7.    (aset a (+ (* index 2) 1) y)))
  8.  
  9. (define (neon-spline1)
  10.   (let* ((a (cons-array 6 'byte)))
  11.     (set-pt a 0 0 0)
  12.     (set-pt a 1 127 145)
  13.     (set-pt a 2 255 255)
  14.     a))
  15.  
  16. (define (neon-spline2)
  17.   (let* ((a (cons-array 6 'byte)))
  18.     (set-pt a 0 0 0)
  19.     (set-pt a 1 110 150)
  20.     (set-pt a 2 255 255)
  21.     a))
  22.  
  23. (define (neon-spline3)
  24.   (let* ((a (cons-array 6 'byte)))
  25.     (set-pt a 0 0 0)
  26.     (set-pt a 1 100 185)
  27.     (set-pt a 2 255 255)
  28.     a))
  29.  
  30. (define (neon-spline4)
  31.   (let* ((a (cons-array 8 'byte)))
  32.     (set-pt a 0 0 0)
  33.     (set-pt a 1 64 64)
  34.     (set-pt a 2 127 192)
  35.     (set-pt a 3 255 255)
  36.     a))
  37.  
  38. (define (find-hue-offset color)
  39.   (let* ((R (car color))
  40.      (G (cadr color))
  41.      (B (caddr color))
  42.      (max-val (max R G B))
  43.      (min-val (min R G B))
  44.      (delta (- max-val min-val))
  45.      (hue 0))
  46.     (if (= max 0) 0
  47.     (begin
  48.       (cond ((= max-val R) (set! hue (/ (- G B) (* 1.0 delta))))
  49.         ((= max-val G) (set! hue (+ 2 (/ (- B R) (* 1.0 delta)))))
  50.         ((= max-val B) (set! hue (+ 4 (/ (- R G) (* 1.0 delta))))))
  51.       (set! hue (* hue 60))
  52.       (if (< hue 0) (set! hue (+ hue 360)))
  53.       (if (> hue 360) (set! hue (- hue 360)))
  54.       (if (> hue 180) (set! hue (- hue 360)))
  55.       hue))))
  56.  
  57. (define (apply-neon-logo-effect img
  58.                 tube-layer
  59.                 size
  60.                 bg-color
  61.                 glow-color
  62.                 shadow)
  63.   (let* ((tube-hue (find-hue-offset glow-color))
  64.      (shrink (/ size 14))
  65.      (grow (/ size 40))
  66.      (feather (/ size 5))
  67.      (feather1 (/ size 25))
  68.      (feather2 (/ size 12))
  69.      (inc-shrink (/ size 100))
  70.      (shadow-shrink (/ size 40))
  71.      (shadow-feather (/ size 20))
  72.      (shadow-offx (/ size 10))
  73.      (shadow-offy (/ size 10))
  74.      (width (car (gimp-drawable-width tube-layer)))
  75.      (height (car (gimp-drawable-height tube-layer)))
  76.      (glow-layer (car (gimp-layer-new img width height RGBA_IMAGE "Neon Glow" 100 NORMAL)))
  77.      (bg-layer (car (gimp-layer-new img width height RGB_IMAGE "Background" 100 NORMAL)))
  78.      (shadow-layer (if (= shadow TRUE)
  79.                (car (gimp-layer-new img width height RGBA_IMAGE "Shadow" 100 NORMAL))
  80.                0))
  81.      (selection 0)
  82.      (old-fg (car (gimp-palette-get-foreground)))
  83.      (old-bg (car (gimp-palette-get-background))))
  84.     (gimp-image-resize img width height 0 0)
  85.     (gimp-image-add-layer img bg-layer 1)
  86.     (if (not (= shadow 0))
  87.     (begin
  88.       (gimp-image-add-layer img shadow-layer 1)
  89.       (gimp-edit-clear shadow-layer)))
  90.     (gimp-image-add-layer img glow-layer 1)
  91.  
  92.     (gimp-palette-set-background '(0 0 0))
  93.     (gimp-selection-layer-alpha tube-layer)
  94.     (set! selection (car (gimp-selection-save img)))
  95.     (gimp-selection-none img)
  96.  
  97.     (gimp-edit-clear glow-layer)
  98.     (gimp-edit-clear tube-layer)
  99.  
  100.     (gimp-palette-set-background bg-color)
  101.     (gimp-edit-fill bg-layer BG-IMAGE-FILL)
  102.  
  103.     (gimp-selection-load selection)
  104.     (gimp-palette-set-background '(255 255 255))
  105.     (gimp-edit-fill tube-layer BG-IMAGE-FILL)
  106.     (gimp-selection-shrink img shrink)
  107.     (gimp-palette-set-background '(0 0 0))
  108.     (gimp-edit-fill selection BG-IMAGE-FILL)
  109.     (gimp-edit-clear tube-layer)
  110.  
  111.     (gimp-selection-none img)
  112.     (if (not (= feather1 0)) (plug-in-gauss-rle 1 img tube-layer feather1 TRUE TRUE))
  113.     (gimp-selection-load selection)
  114.     (if (not (= feather2 0)) (plug-in-gauss-rle 1 img tube-layer feather2 TRUE TRUE))
  115.  
  116.     (gimp-selection-feather img inc-shrink)
  117.     (gimp-selection-shrink img inc-shrink)
  118.     (gimp-curves-spline tube-layer 4 6 (neon-spline1))
  119.  
  120.     (gimp-selection-load selection)
  121.     (gimp-selection-feather img inc-shrink)
  122.     (gimp-selection-shrink img (* inc-shrink 2))
  123.     (gimp-curves-spline tube-layer 4 6 (neon-spline2))
  124.  
  125.     (gimp-selection-load selection)
  126.     (gimp-selection-feather img inc-shrink)
  127.     (gimp-selection-shrink img (* inc-shrink 3))
  128.     (gimp-curves-spline tube-layer 4 6 (neon-spline3))
  129.  
  130.     (gimp-layer-set-preserve-trans tube-layer 1)
  131.     (gimp-selection-layer-alpha tube-layer)
  132.     (gimp-selection-invert img)
  133.     (gimp-palette-set-background glow-color)
  134.     (gimp-edit-fill tube-layer BG-IMAGE-FILL)
  135.  
  136.     (gimp-selection-none img)
  137.     (gimp-layer-set-preserve-trans tube-layer 0)
  138.     (gimp-curves-spline tube-layer 4 8 (neon-spline4))
  139.  
  140.     (gimp-selection-load selection)
  141.     (gimp-selection-grow img grow)
  142.     (gimp-selection-invert img)
  143.     (gimp-edit-clear tube-layer)
  144.     (gimp-selection-invert img)
  145.  
  146.     (gimp-selection-feather img feather)
  147.     (gimp-edit-fill glow-layer BG-IMAGE-FILL)
  148.  
  149.     (if (not (= shadow 0))
  150.     (begin
  151.           (gimp-selection-load selection)
  152.           (gimp-selection-grow img grow)
  153.       (gimp-selection-shrink img shadow-shrink)
  154.       (gimp-selection-feather img shadow-feather)
  155.       (gimp-selection-translate img shadow-offx shadow-offy)
  156.       (gimp-palette-set-background '(0 0 0))
  157.       (gimp-edit-fill shadow-layer BG-IMAGE-FILL)))
  158.     (gimp-selection-none img)
  159.  
  160.     (gimp-layer-set-name tube-layer "Neon Tubes")
  161.     (gimp-palette-set-background old-bg)
  162.     (gimp-palette-set-foreground old-fg)
  163.     (gimp-image-remove-channel img selection)))
  164.  
  165. (define (script-fu-neon-logo-alpha img
  166.                    tube-layer
  167.                    size
  168.                    bg-color
  169.                    glow-color
  170.                    shadow)
  171.   (begin
  172.     (gimp-undo-push-group-start img)
  173.     (apply-neon-logo-effect img tube-layer size bg-color glow-color shadow)
  174.     (gimp-undo-push-group-end img)
  175.     (gimp-displays-flush)))
  176.  
  177. (script-fu-register "script-fu-neon-logo-alpha"
  178.             _"<Image>/Script-Fu/Alpha to Logo/Neon..."
  179.             "Neon logos"
  180.             "Spencer Kimball"
  181.             "Spencer Kimball"
  182.             "1997"
  183.             "RGBA"
  184.                     SF-IMAGE      "Image" 0
  185.                     SF-DRAWABLE   "Drawable" 0
  186.             SF-ADJUSTMENT _"Effect Size (pixels * 5)" '(150 2 1000 1 10 0 1)
  187.             SF-COLOR      _"Background Color" '(0 0 0)
  188.             SF-COLOR      _"Glow Color" '(38 211 255)
  189.             SF-TOGGLE     _"Create Shadow" FALSE
  190.             )
  191.  
  192. (define (script-fu-neon-logo text
  193.                  size
  194.                  font
  195.                  bg-color
  196.                  glow-color
  197.                  shadow)
  198.   (let* ((img (car (gimp-image-new 256 256 RGB)))
  199.      (border (/ size 4))
  200.      (tube-layer (car (gimp-text-fontname img -1 0 0 text border TRUE size PIXELS font))))
  201.     (gimp-image-undo-disable img)
  202.     (gimp-layer-set-name tube-layer text)
  203.     (apply-neon-logo-effect img tube-layer size bg-color glow-color shadow)
  204.     (gimp-image-undo-enable img)
  205.     (gimp-display-new img)))
  206.  
  207. (script-fu-register "script-fu-neon-logo"
  208.             _"<Toolbox>/Xtns/Script-Fu/Logos/Neon..."
  209.             "Neon logos"
  210.             "Spencer Kimball"
  211.             "Spencer Kimball"
  212.             "1997"
  213.             ""
  214.             SF-STRING     _"Text" "NEON"
  215.             SF-ADJUSTMENT _"Font Size (pixels)" '(150 2 1000 1 10 0 1)
  216.             SF-FONT       _"Font" "-*-Blippo-*-*-*-*-24-*-*-*-*-*-*-*"
  217.             SF-COLOR      _"Background Color" '(0 0 0)
  218.             SF-COLOR      _"Glow Color" '(38 211 255)
  219.             SF-TOGGLE     _"Create Shadow" FALSE
  220.             )
  221.